package com.hll.controller;

import com.hll.pojo.Student;
import com.hll.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class StudentController {
    @Resource
    private StudentService studentService;

    /**
     * 查询全部
     * @param model
     * @return
     */
    @RequestMapping("/userAll")
    public String findAll(Model model){
        List<Student> list = studentService.findAll();
        model.addAttribute("li",list);
        return "/user/userAll";
    }

    /**
     * 删除
     * @param sid
     * @return
     */
    @RequestMapping("/delete")
    public String delete(@RequestParam("sid") int sid){
        studentService.delete(sid);
        return "redirect:/userAll";
    }

    /**
     * 查一个
     * @param sid
     * @param model
     * @return
     */
    @RequestMapping("/findOne")
    public String findOne(@RequestParam("sid")int sid,Model model){
        Student one = studentService.findOne(sid);
        model.addAttribute("one",one);
        return "/user/update";
    }

    /**
     * 修改
     * @param student
     * @return
     */
    @RequestMapping("/update")
    public String update(Student student){
        studentService.update(student);
        return "redirect:/userAll";
    }

    /**
     * 去添加
     * @return
     */
    @RequestMapping("/toInsert")
    public String toInsert(){
        return "/user/insert";
    }
    @RequestMapping("/insert")
    public String insert(Student student){
        studentService.insert(student);
        return "redirect:/userAll";
    }

}
